﻿using System.Web.Mvc;
using AFT.Parking.Bizlogic.Customers;
using AFT.Parking.Entity;
using AFT.Parking.Foundation.Extensions;


namespace AFT.Parking.WebSite.Controllers
{
   
    public class AccountController : BaseController
    {
        public ActionResult Login(string backUrl)
        {
            if (IsLogin)
            {
                if (backUrl.IsNullOrEmpty())
                    return Redirect("/employee/EmployeeRecordList");
                else
                    return Redirect(backUrl);
            }
            return View();
        }
        [HttpPost]
        public ActionResult Login(Customer model,string backUrl)
        {
            bool isFlag = true;
            string errors = string.Empty;
            if (model.UserName.IsNullOrEmpty())
            {
                isFlag = false;
                errors = "用户名不能为空；";
            }
            if (model.Password.IsNullOrEmpty())
            {
                isFlag = false;
                errors += "密码不能为空；";
            }
            if (isFlag)
            {
                var customerBiz = new CustomerBiz().Login(model);
                if (customerBiz.Value)
                {
                    UpdateUserSession(customerBiz.Result);
                    Session["menus"] = Bizlogic.Menus.MenusBiz.Menus;
                  //  string backUrl = Request.QueryString["backUrl"];
                    if (backUrl.IsNullOrEmpty())
                        backUrl = "/";
                    return Redirect(backUrl);
                }
                else
                    errors = customerBiz.Message;
            }

            ViewBag.Message = errors;
            return View();
        }

        public ActionResult SignOut()
        {
            Session.Clear();
            return RedirectToAction("login","account");
        }
    }
}